package com.itheima.Demo01.demo06;

import java.util.concurrent.atomic.AtomicInteger;

public class Test01 {
    public static void main(String[] args) {
        method01();
        method02();
        method03();
        method04();

    }

    private static void method04() {
        AtomicInteger A = new AtomicInteger(10);
        int andAdd = A.getAndSet(20);
        System.out.println(andAdd);                    //30
        System.out.println(A.get());                   //30
    }

    private static void method03() {
        AtomicInteger A = new AtomicInteger(10);
        int andAdd = A.getAndIncrement();
        System.out.println(andAdd);                   //11
        System.out.println(A.get());                 //11
    }

    private static void method02() {
        AtomicInteger A = new AtomicInteger(10);
        int andAdd = A.incrementAndGet();
        System.out.println(andAdd);                    //10
        System.out.println(A.get());                    //11

    }

    private static void method01() {
        AtomicInteger A = new AtomicInteger(10);
        int i = A.addAndGet(20);
        System.out.println(i);                      //10
        System.out.println(A.get());               //20
    }
}
